var vm_hezengdetail = new Vue({
    el : "#hezengdetail",
    data : {
        deptid : $("#deptid").val(),		// 单位ID
        piciid : "",//$("#piciid").val(),		// 专家变动批次ID

        biandonglist : [],// 专家变动列表custom
        biandongid : '',//变动id
        biandong : {},//变动表

        shiwu : {},

        zhuanjialist : [],//本单位专家列表
        zhuanjianame : '',

        zhuanzidanweilist : [],//单位列表
        zhuanzhidanweilist : [],
        zhuanzidanweiname : '',
        zhuanzhidanweiname : '',

        shenhejilulist : [],

        //查询用字段
        zhuanjiamingcheng : '',
        biandongleixing : '8',
        biandongriqi : '',
        //

        editflag : '',//1添加 2修改
    },
    created : function(){
        var _this = this;

        _this.bindZhuanliList();//转隶列表，deptid

    },
    methods : {

        // 根据单位ID查询下级单位
        bindZhuanliList : function(){
            var _this = this;

            var biandong_layer = layer.open({type:3});
            $.post('/system/zhuanjiabiandongdetail/custombiandonglist', {
                deptid : _this.deptid,
                zhuanjiamingcheng : _this.zhuanjiamingcheng,
                biandongleixing : _this.biandongleixing,
                biandongriqi : _this.biandongriqi,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandong_layer);

                if (ppData != null) {
                    var data = ppData;
                    _this.biandonglist = data;
                }
            },"json");
        },

        bindZhuanli : function(){
            var _this = this;

            var biandong_layer = layer.open({type:3});
            $.post('/system/zhuanjiabiandongdetail/findone', {
                id : _this.biandongid,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandong_layer);

                if(ppData != null){

                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.biandong = data;
                        _this.biandong.id = _this.biandongid;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        toAdd:function(){

            $("#biandongleixing_div").attr("style","display:none");
            $("#biandonriqi_div").attr("style","display:none");
            $("#myModalLabel").html("添加专家转隶情况");
            $("#modal-dialog").attr("style","width:1200px;");
            $("#biandongModal").modal();

            this.bindZhuanzidanweiList();
            this.bindZhuanzhidanweiList();

            this.zhuanjianame = '';
            this.bindZhuanjiaList();

            this.biandong = {};
            this.editflag = 1;
        },

        //添加
        add:function(){
            var _this = this;
            if (_this.checkInputData()) {
                var biandong_layer = layer.open({type: 3});
                $.post('/system/zhuanjiabiandongdetail/save', {
                    //biandongpiciid: _this.piciid,
                    deptid : _this.deptid,
                    zhuanjiaid : _this.biandong.zhuanjiaid,
                    biandongleixing : '8',
                    biandongriqi : _this.biandong.biandongriqi,
                    //zhuanzidanwei : _this.biandong.zhuanzidanwei,
                    zhuanzhidanwei : _this.biandong.zhuanzhidanwei,
                    shuoming : _this.biandong.shuoming,
                    rdm: Math.random()
                }, function (ppData) {
                    layer.close(biandong_layer);
                    if (ppData != null) {

                        if (ppData.result == "1") {
                            layer.open({
                                time: 1000,
                                btn: [],
                                content: "添加成功!",
                            });

                            _this.refresh();
                            $("#biandongModal").modal('hide');

                        } else {
                            layer.alert(ppData.message);
                        }
                    }
                }, "json");
            }
        },

        toModify:function(ppBiandongId){

            $("#biandongleixing_div").attr("style","display:none");
            $("#biandonriqi_div").attr("style","display:none");
            $("#myModalLabel").html("修改专家转隶信息");
            $("#modal-dialog").attr("style","width:1200px;");
            $("#biandongModal").modal();

            this.biandongid = ppBiandongId;

            this.bindZhuanzidanweiList();
            this.bindZhuanzhidanweiList();

            this.zhuanjianame = '';
            this.bindZhuanjiaList();

            this.biandong = {};
            this.editflag = 2;
            // 绑定变动
            this.bindZhuanli();
        },

        // 修改信息
        modify : function(){
            var _this = this;
            if (_this.checkInputData()) {
                var biandong_layer = layer.open({type: 3});
                $.post('/system/zhuanjiabiandongdetail/save', {
                    id: _this.biandongid,
                    zhuanjiaid : _this.biandong.zhuanjiaid,
                    biandongleixing : '8',
                    biandongriqi : _this.biandong.biandongriqi,
                    zhuanzidanwei : _this.biandong.zhuanzidanwei,
                    zhuanzhidanwei : _this.biandong.zhuanzhidanwei,
                    shuoming : _this.biandong.shuoming,
                    rdm: Math.random()
                }, function (ppData) {
                    layer.close(biandong_layer);
                    if (ppData != null) {

                        if (ppData.result == "1") {
                            layer.open({
                                time: 1000,
                                btn: [],
                                content: "修改成功!",
                            });

                            _this.refresh();
                            $("#biandongModal").modal('hide');

                        } else {
                            layer.alert(ppData.message);
                        }
                    }
                }, "json");
            }
        },

        Delete:function(ppId){
            var _this = this;

            var biandong_layer = layer.open({type:3});
            $.post('/system/zhuanjiabiandongdetail/deletebyid', {
                id : ppId,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandong_layer);

                if(ppData != null){

                    if(ppData.result == "1"){
                        layer.open({
                            time: 1000,
                            btn: [],
                            content: "删除成功!",
                        });

                        _this.refresh();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        //检查项目数据
        checkInputData : function() {
            if (!$.trim(this.biandong.zhuanjiaid)) {
                layer.alert("请选择变动的专家！");
                return false;
            }

            if (!$.trim(this.biandong.zhuanzhidanwei)) {
                layer.alert("请选择转至单位！");
                return false;
            }

            return true;
        },

        getDate:function(){
            var _this = this;

            _this.biandong.biandongriqi=$("#biandongriqi").val();
        },

        refresh:function(){
            var _this = this;

            //
            _this.bindZhuanliList();
        },

        bindZhuanjiaList : function(){
            var _this = this;

            var biandong_layer = layer.open({type:3});
            $.post('/system/deptzhuanjia/find_by_deptid', {
                deptid : _this.deptid,
                zhuanjianame: _this.zhuanjianame,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandong_layer);

                if (ppData != null) {
                    var data = ppData;
                    _this.zhuanjialist = data;
                }
            },"json");
        },

        bindZhuanzidanweiList:function(){
            var _this = this;

            var biandong_layer = layer.open({type:3});
            $.post('/system/deptdetail/findvalid', {
                deptname : _this.zhuanzidanweiname,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandong_layer);

                if (ppData != null) {
                    if (ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.zhuanzidanweilist = data;
                    }
                }

            },"json");
        },

        bindZhuanzhidanweiList:function(){
            var _this = this;

            var biandong_layer = layer.open({type:3});
            $.post('/system/deptdetail/findvalid', {
                deptname : _this.zhuanzhidanweiname,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandong_layer);

                if (ppData != null) {
                    if (ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.zhuanzhidanweilist = data;
                    }
                }

            },"json");
        },

        getZhuanzidanweiId:function(){
            this.biandong.zhuanzidanwei=$("#zhuanzidanwei").val();
        },

        getZhuanzhidanweiId:function(){
            this.biandong.zhuanzhidanwei=$("#zhuanzhidanwei").val();
        },

        Submit:function(ppId){
            var _this = this;

            var biandong_layer = layer.open({type:3});
            $.post('/system/renwu/submit_custom', {
                id : ppId,
                deptid : _this.deptid,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandong_layer);

                if (ppData != null) {
                    if (ppData.result==1){
                        layer.alert("提交成功");
                        _this.refresh();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        showShenhejiluModel:function(ppShiwuId){
            var _this = this;

            $("#shenhejiluModalLabel").html("审核记录");
            $("#shenhejiluModal").modal();

            _this.bindShenhejilu(ppShiwuId);
        },

        bindShenhejilu:function(ppShiwuId){
            var _this = this;

            var biandong_layer = layer.open({type:3});
            $.post('/system/renwu/findshenhejilu', {
                shiwuid : ppShiwuId,
                rdm : Math.random()
            },function(ppData) {
                layer.close(biandong_layer);

                if (ppData != null) {
                    var data = ppData;
                    _this.shenhejilulist = data.resultContent;
                }
            },"json");
        },

    },
})